{extend name="adminblue/base" /}
{block name="resources"/}
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>
<link href="__STATIC__/blue/css/order/ns_orderlist.css" rel="stylesheet" type="text/css" />
<style>
.mytable.select td{padding-bottom:0;}
.mytable.select div{display:inline-block;margin:0 10px 10px 0;}
.mytable.select #more_search{display: block;}
.table-class tbody td a {margin-left: 0;}
.order-tool{display: inline;position: absolute;margin-top: 10px;margin-left: 16px;}
.to-fixed{position: fixed;width: 85.5%;top: 50px;box-shadow: 0 2px 6px 0 rgba(0,0,0,.3);z-index: 5;}
.btn-common-white{line-height: 20px;outline: none;}
.ns-main{margin-top: 0;}
.seller_memo{background: #FFF9DF!important;color: #D09B4C;}
</style>
{/block}
<!-- {1block name="warm_prompt"}{/block} -->
{block name="right_tab_tip"}{/block}
{block name="main"}
<input type="hidden" id="order_id" />
<input type="hidden" id="print_select_ids" />
<input type="hidden" id="order_status" value="{$status}" />

	<table class="mytable">
		<tr>
			<th align="left">
				<button class="btn-common" onclick="dataExcel()">导出数据</button>
				<a class="btn-common-white" id="PrintOrder" href="javascript:;">
					<i class="fa fa-print"></i>
					<span>打印订单</span>
				</a>
				{if condition="$status neq '' && $status neq 0 "}
					{if condition="$status eq 1"}
					<a class="btn-common-white" id="BatchShipment" href="javascript:;">
						<span>批量发货</span>
					</a>
					{/if}
					{in name="$status" value="1,2"}
					<a class="btn-common-white" id="PrintShipping" href="javascript:;">
						<i class="fa fa-print"></i>
						<span>打印出库单</span>
					</a>
					<a class="btn-common-white" id="BatchPrint" href="javascript:;">
						<i class="fa fa-print"></i>
						<span>批量打印快递单</span>
					</a>
					<a class="btn-common-white" id="BatchPrintinvoice" href="javascript:;">
						<i class="fa fa-print"></i>
						<span>批量打印发货单</span>
					</a>
					{/in}
					{if condition="$status eq 5 "}
					<a class="btn-common-white" href="javascript:batchDelete();">
						<i class="fa fa-trash"></i>
						<span>批量删除</span>
					</a>
					{/if}
				{/if}
			</th>
			<th>
				<span>下单时间：</span>
				<input type="text" id="startDate" class="input-common middle" placeholder="请选择开始日期" onclick="WdatePicker()" />
				&nbsp;-&nbsp;
				<input type="text" id="endDate" placeholder="请选择结束日期" class="input-common middle" onclick="WdatePicker()" />
				<button class="btn-common-white more-search"><i class="fa fa-chevron-down"></i></button>
				<button class="btn-common" onclick="searchData()">搜索</button>

				<!-- 更多搜索 -->
				<div class="more-search-container">
					<dl>
						<dt>订单编号：</dt>
						<dd>
							<input id="orderNo" class="input-common middle" type="text" />
						</dd>
					</dl>
					<dl>
						<dt>收货人姓名：</dt>
						<dd>
							<input id="userName" class="input-common middle" type="text" />
						</dd>
					</dl>
					<dl>
						<dt>收货人手机号：</dt>
						<dd>
							<input id="receiverMobile" class="input-common middle" type="text" />
						</dd>
					</dl>
					<dl>
						<dt>支付方式：</dt>
						<dd>
							<select id="payment_type" class="select-common middle">
								<option value="">全部</option>
								<option value="1">微信</option>
								<option value="2">支付宝</option>
								<option value="10">线下支付</option>
							</select>
						</dd>
					</dl>
					<dl>
						<dt></dt>
						<dd>
							<button class="btn-common" onclick="searchData()">搜索</button>
						</dd>
					</dl>
				</div>
			</th>
		</tr>
	</table>
		
	<table class="table-class">
		<colgroup>
			<col width="2%">
			<col width="24%">
			<col width="14%">
			<col width="10%">
			<col width="10%">
			<col width="10%">
			<col width="10%">
			<col width="10%">
			<col width="10%">
		</colgroup>
		<thead>
			<tr align="center">
				<th>
					<i class="checkbox-common"><input type="checkbox" onclick="CheckAll(this)" id="check"></i>
				</th>
				<th>商品信息</th>
				<th>商品清单</th>
				<th>买家</th>
				<th>收货信息</th>
				<th>订单金额</th>
				<th>交易状态</th>
				<th>配送方式</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody></tbody>
	</table>
</div>

{/block}
{block name="script"}

{include file="adminblue/Order/orderAction"/}
{include file="adminblue/Order/orderRefundAction"/}
<!-- 订单打印 -->
{include file="adminblue/Order/orderPrintAction"/}
<script type="text/javascript">
$(window).scroll(function(){
	var scrollTop = $(window).scrollTop();
	if(scrollTop > 140){
		$("nav.order-nav").addClass("to-fixed");
	}else{
		$("nav.order-nav").removeClass("to-fixed");
	}
})
$(function () { 
	$("[data-toggle='popover']").popover();
});
function searchData(){
	$(".more-search-container").slideUp();
	LoadingInfo(1);
}

function LoadingInfo(page_index) {
	var start_date = $("#startDate").val();
	var end_date = $("#endDate").val();
	var user_name = $("#userName").val();
	var order_no = $("#orderNo").val();
	var receiver_mobile = $("#receiverMobile").val();
	var order_status = $("#order_status").val();
	var payment_type = $("#payment_type").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/tuangou/pintuanorderlist')}",
		data : {
			"page_index" : page_index,
			"page_size" : $("#showNumber").val(),
			"start_date" : start_date,
			"end_date" : end_date,
			"user_name" : user_name,
			"order_no" : order_no,
			"order_status" : order_status,
			"receiver_mobile" : receiver_mobile,
			"order_status" : order_status,
			"payment_type" : payment_type,
			"tuangou_group_id" : "{$tuangou_group_id}"
		},
		success : function(data) {
			//alert(JSON.stringify(data["data"][1]['order_item_list']));
			if (data["data"].length > 0) {
				//alert(JSON.stringify(data["data"][1]['order_item_list'][0]["goods_sku_list"]));
				$(".table-class tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {
					var html = '';
					var out_trade_no = data["data"][i]["out_trade_no"];//交易号
					var order_id = data["data"][i]["order_id"];//订单id
					var order_no = data["data"][i]["order_no"];//订单编号
					var create_time = timeStampTurnTime(data["data"][i]["create_time"]);//下单时间
					var pic_cover_micro = data["data"][i]["order_item_list"][0]["picture"]['pic_cover_micro'];//商品图
					var goods_id = data["data"][i]["order_item_list"][0]["goods_id"];//商品id
					var goods_name = data["data"][i]["order_item_list"][0]["goods_name"];
					var sku_name = data["data"][i]["order_item_list"][0]["sku_name"];//商品sku
					var price = data["data"][i]["order_item_list"][0]["price"];//商品价格
					var num = data["data"][i]["order_item_list"][0]["num"];//购买数量
					var order_money = data["data"][i]["order_money"];//订单金额
					var shipping_money = data["data"][i]["shipping_money"];//运费
					var seller_memo = data["data"][i]["seller_memo"];//订单备注
					var goods_code = data["data"][i]["order_item_list"][0]["code"];
					var shipping_type_name = data['data'][i]['shipping_type_name']['type_name'];//配送方式

					var row=1;//订单数量，用于设置跨行
					if(data["data"][i]["order_item_list"].length!=null){
						row=data["data"][i]["order_item_list"].length;
					}

					html += '<tr>';
					
					html += '<td rowspan="'+row+'"><i class="checkbox-common"><input id="'+out_trade_no+'" type="checkbox"  value="'+order_id+'" name="sub"></i></td>';
					
					html += '<td>';
					
					html += '<div style="font-size: 12px;color: #126AE4;margin-bottom:5px;">';
// 					html +='<span>订单编号：'+order_no+' 交易号：'+out_trade_no+'</span><span>下单时间：'+create_time+'</span>';
					html +='<span>订单编号：'+order_no+'</span>&nbsp;<span>下单时间：'+create_time+'</span>';
				
					html += '</div>';
					
					html += '<div class="product-img"><img src="'+__IMG(pic_cover_micro)+'"></div>';
					html += '<div class="product-infor">';
					html += '<a href="'+__URL('SHOP_MAIN/goods/goodsinfo?goodsid='+goods_id)+'" target="_blank" style="color:#333;">'+goods_name+'</a>';
					if(sku_name != null && sku_name != ""){
						html += '<p class="specification" style="margin-bottom: 0px;"><span style="color:#8e8c8c;font-size:12px;">'+sku_name+'</span></p>';
					}
					if(goods_code != null && goods_code != ""){
						html += '<p class="specification"><span style="color:#8e8c8c;font-size:12px;">编码&nbsp;&nbsp;'+goods_code+'</span></p></div>';
					}
					html += '</div></td>';
					
					//订单数量大于1个，调整样式
					html += '<td>';
						html += '<div class="cell" style="display: inline-block;"><span>'+price+'元</span></div>';
						html += '<div class="cell" style="display: inline-block;float:right;">'+num+'件</div>';
					
					//调价
					if(data["data"][i]["order_item_list"][0]['adjust_money'] != 0){
						var adjust_money = data["data"][i]["order_item_list"][0]["adjust_money"];//调教
						html += '<div class="cell" style="display: inline-block;"><span>(调价：'+adjust_money+'元)</span></div>';
					}
					if(	data["data"][i]["order_item_list"][0]['refund_status'] != 0){
						//退款
						var order_goods_id = data["data"][i]["order_item_list"][0]["order_goods_id"];//订单项id
						var status_name = data["data"][i]["order_item_list"][0]["status_name"];//状态

						//订单数量大于1个，调整样式
						if(data["data"][i]["order_item_list"].length>1){
							html +='<a href="'+__URL('ADMIN_MAIN/order/orderrefunddetail?itemid='+order_goods_id)+'" style="margin:5px 0 10px 0;display:block;text-align:center;">'+status_name+'</a>';
						}else{
							html +='<a href="'+__URL('ADMIN_MAIN/order/orderrefunddetail?itemid='+order_goods_id)+'" style="margin:5px 0 10px 0;display:block;">'+status_name+'</a>';
						}
						for(var m = 0; m < data["data"][i]["order_item_list"][0]["refund_operation"].length; m++){
							var operation_type = data["data"][i]["order_item_list"][0]["refund_operation"][m]['no'];//选项类型
							var color = data["data"][i]["order_item_list"][0]["refund_operation"][m]['color'];
							var order_goods_id = data["data"][i]["order_item_list"][0]['order_goods_id'];//订单项id
							var refund_require_money = data["data"][i]['order_item_list'][0]["refund_require_money"];//退款金额
							var name = data["data"][i]["order_item_list"][0]["refund_operation"][m]['name'];//退款状态
							html += '<a style="display:block;margin-bottom:5px;color:'+color+';text-align:center;" href="javascript:refundOperation(\''+operation_type+'\','+order_id+','+order_goods_id+','+refund_require_money+')">'+name+'</a>';
						}
					}
					html += '</td>';
					
					html += '<td rowspan="'+row+'" style="text-align:center"><div class="cell">'+data["data"][i]["user_name"]+'<br/>';
					html += '<i class="'+data["data"][i]["order_from_tag"]+'" style="color:#666;"><i></div></td>';
					
					html += '<td rowspan="'+row+'" style="text-align:center">';
					//地址
					var address = data["data"][i]["receiver_province_name"]+data["data"][i]["receiver_city_name"]+data["data"][i]["receiver_district_name"]+data["data"][i]["receiver_address"];
					html += '<div style="text-align:left;"><span class="expressfee">'+data["data"][i]["receiver_name"]+'</span><br/><span class="expressfee">'+data["data"][i]["receiver_mobile"]+'</span>';
					if(data["data"][i]["fixed_telephone"] != ""){
						html += '<br><span>'+data["data"][i]["fixed_telephone"]+'</span>';
					}
					html += '<br/><span class="expressfee">'+address+'</span>';
					html += '</div></td>';
					
					html += '<td rowspan="'+row+'" style="text-align:center">';
					html += '<div class="cell"><b class="netprice" style="color: #FF6600;font-size: 14px;font-weight: normal;">'+order_money+'</b><br/>';
					html += '<span class="expressfee">(含配送费:'+shipping_money+'元)</span><br/>';
					html += '<span class="expressfee">'+data["data"][i]["pay_type_name"]+'</span></div></td>';

					html += '<td rowspan="'+row+'"><div class="business-status" style="text-align:center">'+data["data"][i]["status_name"]+'<br></div></td>';
					html += '<td rowspan="'+row+'"><div class="business-status" style="text-align:center">'+ shipping_type_name +'<br></div></td>';
					html += '<td rowspan="'+row+'" style="text-align:center;">';
					html += '<a style="display:block;margin-bottom:5px;" href="'+__URL('ADMIN_MAIN/order/orderdetail?order_id='+order_id)+'">订单详情</a>';

					if(data["data"][i]["operation"] != ''){
						for(var m = 0; m < data["data"][i]["operation"].length; m++){
							if(data["data"][i]["operation"][m]['no'] == "seller_memo"){
								html += '<a style="display:block;margin-bottom:5px;color:'+data["data"][i]["operation"][m]["color"]+'" href="javascript:operation(\''+data["data"][i]["operation"][m]['no']+'\','+data["data"][i]["order_id"]+')" >'+data["data"][i]["operation"][m]['name']+'</a>';
							}else{
								html += '<a style="display:block;margin-bottom:5px;color:'+data["data"][i]["operation"][m]["color"]+'" href="javascript:operation(\''+data["data"][i]["operation"][m]['no']+'\','+data["data"][i]["order_id"]+')" >'+data["data"][i]["operation"][m]['name']+'</a>';
							}
						}
					}
					html +='</td></tr>';

					if(seller_memo.length > 0){
						html += '<tr><td colspan="10" class="seller_memo">卖家备注：'+seller_memo+'</td></tr>';
					}
					if(i < data["data"].length - 1){
						html += '<tr style="height:10px;"><td style="border-bottom:solid #E1E6F0;border-width:0 0 1px 0;" colspan="10"></td></tr>';
					}
					
					//循环订单项
					//前边已经加载过一次了，所以从第二次开始循环
					// for(var j = 1; j < data["data"][i]["order_item_list"].length; j++){
					// 	var pic_cover_micro = data["data"][i]["order_item_list"][j]["picture"]['pic_cover_micro'];//商品图
					// 	var goods_id = data["data"][i]["order_item_list"][j]["goods_id"];//商品id
					// 	var goods_name = data["data"][i]["order_item_list"][j]["goods_name"];//商品名称
					// 	var sku_name = data["data"][i]["order_item_list"][j]["sku_name"];//sku名称
					// 	var price = data["data"][i]["order_item_list"][j]["price"];//价格
					// 	var num = data["data"][i]["order_item_list"][j]["num"];//购买数量						
					// 	var goods_code = data["data"][i]["order_item_list"][j]["code"];
					// 	html += '<tr calss="js-child-order">';
					// 	html += '<td colspan="1">';
					// 	html += '<div class="product-img"><img src="'+__IMG(pic_cover_micro)+'"></div>';
					// 	html += '<div class="product-infor">';
					// 	html += '<a class="name" href="'+__URL('SHOP_MAIN/goods/goodsinfo?goodsid='+goods_id)+'" target="_blank" style="color:#333;">'+goods_name+'</a>';
					// 	if(sku_name != null && sku_name != ''){
					// 		html += '<p class="specification" style="margin-bottom: 0px;"><span style="color:#8e8c8c;font-size:12px;">'+sku_name+'</span></p>';
					// 	}
					// 	if(goods_code != null && goods_code != ''){
					// 		html += '<p class="specification"><span style="color:#8e8c8c;font-size:12px;">'+goods_code+'</span></p>';
					// 	}
						
					// 	html += '</div></td>';

					// 	//只给中间的商品加
					// 	if((j+1) != data["data"][i]["order_item_list"].length){
					// 		html += '<td style="border-left:0px solid #fff;border-bottom:1px solid #e5e5e5;">';//商品信息与商品清单的分割线
					// 	}else{
					// 		html += '<td style="border-left:0px solid #fff;">';//商品信息与商品清单的分割线
					// 	}

					// 	//添加赠品标识
					// 	html += '<div class="cell" style="display: inline-block;"><span>'+price+'元</span></div>';
					// 	html += '<div class="cell" style="display: inline-block;float:right">'+num+'件</div>';
					// 	//调价
					// 	if(data["data"][i]["order_item_list"][j]['adjust_money'] != 0){
					// 		var adjust_money = data["data"][i]["order_item_list"][j]["adjust_money"];
					// 		html += '<div class="cell" style="display: inline-block;"><span>(调价：'+adjust_money+'元)</span></div>';
					// 	}
					// 	if(data["data"][i]["order_item_list"][j]['refund_status'] != 0){
					// 		//退款
					// 		var order_goods_id = data["data"][i]["order_item_list"][j]["order_goods_id"];//订单项id
					// 		var status_name = data["data"][i]["order_item_list"][j]["status_name"];//订单状态
					// 		html +='<br><a href="'+__URL('ADMIN_MAIN/order/orderrefunddetail?itemid='+order_goods_id)+'" style="margin:5px 0 10px 0;display:block;text-align:center;">'+status_name+'</a>';
					// 		for(var m = 0; m < data["data"][i]["order_item_list"][j]["refund_operation"].length; m++){
					// 			var operation_type = data["data"][i]["order_item_list"][j]["refund_operation"][m]['no'];//选项类型
					// 			var color = data["data"][i]["order_item_list"][j]["refund_operation"][m]['color'];
					// 			var order_goods_id = data["data"][i]["order_item_list"][j]['order_goods_id'];//订单项id
					// 			var refund_require_money = data["data"][i]['order_item_list'][j]["refund_require_money"];//退款金额
					// 			var name = data["data"][i]["order_item_list"][j]["refund_operation"][m]['name'];//退款状态
					// 			html += '<a style="display:block;margin-bottom:5px;color:'+color+';text-align:center;" href="javascript:refundOperation(\''+operation_type+'\','+order_id+','+order_goods_id+','+refund_require_money+')" >'+name+'</a>';
					// 		}
					// 	}
					// 	html += '</td>';
					// 	html += '</tr>';
					// }
					$(".table-class tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="9">暂无符合条件的订单</td></tr>';
				$(".table-class tbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}

function addmemo(order_id,memo){
	$("#order_id").val(order_id);
	$("#memo").val(memo);
	$("#Memobox").modal("show");
}
/**
 * 订单数据导出
 */
function dataExcel(){
	var start_date = $("#startDate").val();
	var end_date = $("#endDate").val();
	var user_name = $("#userName").val();
	var order_no = $("#orderNo").val();
	var receiver_mobile = $("#receiverMobile").val();
	var order_status = $("#order_status").val();
	var payment_type = $("#payment_type").val();
	var order_ids= new Array();
	$(".table-class tbody input[type = 'checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			order_ids.push($(this).val());
		}
	});
	window.location.href=__URL("ADMIN_MAIN/order/orderDataExcel?start_date="+start_date+"&end_date="+end_date+"&user_name="+user_name+"&order_no="+order_no+"&order_status="+order_status+"&receiver_mobile="+receiver_mobile+"&payment_type="+payment_type+"&order_ids="+order_ids.toString()); 	
}

/**
* 批量删除已关闭订单
*/
function batchDelete(){
	var order_ids= new Array();
	$(".table-class tbody input[type = 'checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			order_ids.push($(this).val());
		}
	});
	if(order_ids.length ==0){
		$( "#dialog" ).dialog({
			buttons: {
				"确定,#0059d6,#fff": function() {
					$(this).dialog('close');
				}
			},
			contentText:"请选择需要操作的记录",
			title:"消息提醒",
		});
		return false;
	}
	delete_order(order_ids);
}
// 点击显示更多搜索
$(".more-search").click(function(){
	$(".more-search-container").slideToggle();
})
</script>
{/block}